package handlers

import (
	"car-trade-hub/models"
	"github.com/gin-gonic/gin"
	"strconv"
)

func CarAdd(c *gin.Context) {
	car_no := c.PostForm("car_no")
	car_name := c.PostForm("car_name")
	car_code := c.PostForm("car_code")
	data := models.Car{
		CarNo:   car_no,
		CarName: car_name,
		CarCode: car_code,
	}
	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
	})
	return
}
func CarOrder(c *gin.Context) {
	order_no := c.PostForm("order_no")
	order_from := c.PostForm("order_from")
	order_to := c.PostForm("order_to")
	order_good := c.PostForm("order_good")
	cid, _ := strconv.Atoi(c.PostForm("cid"))
	data := models.CarOrder{
		OrderNo:   order_no,
		OrderFrom: order_from,
		OrderTo:   order_to,
		OrderGood: order_good,
		Cid:       cid,
	}
	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
